home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1402 < prev    next >
Encoding:
Text File  |  1996-08-06  |  3.3 KB  |  105 lines

  1. Path: atglab.bls.com!Alun.Champion
  2. From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Difficulty hiring people with C++ experience.
  5. Date: 10 Jan 1996 21:00:55 GMT
  6. Organization: Computer People Inc.
  7. Message-ID: <ALUN.CHAMPION.96Jan10160055@g7240065.bridge.bst.bls.com>
  8. References: <gmandelDJAoyx.Kpr@netcom.com> <4ai727$of3@nrchh52.rich.nt.com>
  9.     <4api46$c95@no-names.nerdc.ufl.edu> <4bto2d$gnq@usenet1.interramp.com>
  10.     <gmandelDKL1AF.K22@netcom.com> <4clu0d$623@usenet4.interramp.com>
  11.     <4d12p3$26lq@news.doit.wisc.edu>
  12. NNTP-Posting-Host: bstfirewall.bst.bls.com
  13. In-reply-to: keiter@hp-171.cae.wisc.edu's message of 10 Jan 1996 19:07:15 GMT
  14.  
  15. In article <4d12p3$26lq@news.doit.wisc.edu> keiter@hp-171.cae.wisc.edu (Eric Richard Keiter) writes:
  16.  
  17. : (Tom Donaldson) writes:
  18. ::  When asked about
  19. :: "programming by contract", the response is "Huh?"  The
  20. :: difference between dynamic and static languages?  "Static
  21. :: languages shock you if you shuffle your feet, and dynamic
  22. :: languages are more energetic?"  What are your professional
  23. :: development goals for the next five years?  "To have a job and
  24. :: have lots of free time to play Sega games."
  25.  
  26. : I'm curious... what IS the difference between dynamic and static
  27. : languages?  is it that a dynamic language allows for dynamic memory
  28. : allocation?  or allows aliases?
  29.  
  30. Its to do with the typing mechanisms of the particular language.
  31.  
  32. In C++ (statically typed language with dynamic binding) restricts polymorphic
  33. capabilities to come from a common base class, with virtual specifier on the
  34. member functions. This unnecessary on a dynamic typed language.
  35.  
  36. Example:
  37. In static typed C++
  38.  
  39.    class Common
  40.    {
  41.      public:
  42.        virtual void someFunction(void) = 0;
  43.    };
  44.  
  45.    class Polymorph1 : public Common
  46.    {
  47.      public:
  48.        virtual void someFunction(void);
  49.    };
  50.  
  51.    class Polymorph2 : public Common
  52.    {
  53.      public:
  54.        virtual void someFunction(void);
  55.    };
  56.  
  57.    void func(Common& param)
  58.    {
  59.        param.someFunction();
  60.    }
  61.  
  62. Same thing in dynamic typed C++
  63.  
  64.    class Polymorph1
  65.    {
  66.      public:
  67.        virtual void someFunction(void);
  68.    };
  69.  
  70.    class Polymorph2
  71.    {
  72.      public:
  73.        virtual void someFunction(void);
  74.    };
  75.  
  76.    // No type needed for param - determined at runtime (dynamically)
  77.    void func(param)
  78.    {
  79.        param.someFunction();  // Function invocation determine on the dynamic
  80.    }                  // type of param
  81.  
  82. Does this clarify things ?
  83.  
  84. : and what is programming by contract?  it sounds like an obvious question
  85. : -- is the answer not obvious?
  86.  
  87. The contract between the user and its supplier is the set of requests that
  88. a user can make of that supplier. Programming by contract is the focus
  89. of ensuring the supplier fulfils its contracts. Some aspects of the user
  90. contract is enforced by the compiler like making methods private or protected
  91. but the ability to grant access for particular classes is not possible at the
  92. moment, so some reliance is on the user of the class to not break its contract
  93. with the supplier.
  94. In a multi-threaded environment its very hard to guarentee the contract between
  95. user and supplier because the guarentee of the supplier can be broken by
  96. another thread i.e. values changed etc.. In these situations you lock the
  97. supplier so it can guarentee the contract for the period of that lock.
  98.  
  99. Hope this helps
  100. Regards
  101.  
  102.    -A.
  103. -- 
  104. | A.Champion                |
  105.